package handler

import (
	"github.com/gin-gonic/gin"
	"registration-booking/app/common/request"
	"registration-booking/app/common/response"
	"registration-booking/app/models"
	"registration-booking/app/services"
)

func ComboList(c *gin.Context) {
	if combos, err := services.TestService.ComboList(); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func ComboListPage(c *gin.Context) {
	if combos, err := services.TestService.ComboListPage(); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func GetComboById(c *gin.Context) {
	if combos, err := services.TestService.GetComboById(c.Param("comboId")); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func DeleteCombo(c *gin.Context) {
	if combos, err := services.TestService.DeleteCombo(c.Param("comboId")); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func UpdateComboById(c *gin.Context) {
	var form models.TestCombo
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.UpdateComboById(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func InsertCombo(c *gin.Context) {
	var form models.TestCombo
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.InsertCombo(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func GetComboTimeList(c *gin.Context) {
	if combos, err := services.TestService.GetComboTimeList(); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func GetComboBooking(c *gin.Context) {
	var form request.TestBooking
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if err := services.TestService.GetComboBooking(form, c.Keys["id"].(string)); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, nil)
	}
}

func GetComboBookingHistory(c *gin.Context) {
	if bookingHistory, err := services.TestService.GetComboBookingHistory(c.Keys["id"].(string)); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, bookingHistory)
	}
}

func GetComboBookingHistoryAll(c *gin.Context) {

	var form request.Page
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if bookingHistorys, err := services.TestService.GetComboBookingHistoryAll(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, bookingHistorys)
	}

}

func GetComboBookingHistoryById(c *gin.Context) {
	if bookingHistory, err := services.TestService.GetComboBookingHistoryById(c.Param("bookingId"), c.Keys["id"].(string)); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, bookingHistory)
	}
}

func ProjectListPage(c *gin.Context) {
	var form request.Page
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.ProjectListPage(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func ProjectParent(c *gin.Context) {

	if combos, err := services.TestService.ProjectParent(); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func UpdateParentById(c *gin.Context) {
	var form models.TestProject
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.UpdateParentById(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func InsertProject(c *gin.Context) {
	var form models.TestProject
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.InsertProject(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func DeleteProject(c *gin.Context) {
	if combos, err := services.TestService.DeleteProject(c.Param("projectId")); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func GetComboDateListPage(c *gin.Context) {
	var form request.Page
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.GetComboDateListPage(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func UpdateDateById(c *gin.Context) {
	var form response.ComboTime
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.UpdateDateById(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func InsertTestDate(c *gin.Context) {
	var form response.ComboTimeReq
	if err := c.ShouldBindJSON(&form); err != nil {
		response.Fail(c, request.GetErrorMsg(form, err))
		return
	}

	if combos, err := services.TestService.InsertTestDate(form); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}

func DeleteDate(c *gin.Context) {
	if combos, err := services.TestService.DeleteDate(c.Param("dateId")); err != nil {
		response.Fail(c, err.Error())
	} else {
		response.Success(c, combos)
	}
}
